07. CODE: The Node Class
The Node Class
The Model::Node
class that exists in the current code doesn't contain all the data that would be needed to perfom an A* search. In order to perform a search, it would be ideal for each node to contain at least the following information:
- The g-value for the node.
- The h-value for the node.
- A boolean to indicate if the node has been visited.
- A pointer to the node's parent.
In this exercise, you will fill out the RouteModel::Node
class in route_model.h
, which will extend the Model::Node
class so that the data above, along with a few other useful variables, can be included with each node. Note that the RouteModel::Node
class already has the following private variables:
- An
int
index
. - A pointer to a
RouteModel
object namedparent_model
. This variable is important, as it allows each node to access data stored in the parent model that the node belongs to.
To complete this exercise:
- Add the following public variables to the
RouteModel::Node
class:- A
Node
pointerparent
, which is initialized to anullptr
. - A
float
h_value
, which is initialized to the maximum possible:std::numeric_limits<float>::max()
. - A
float
g_value
, which is initialized to 0.0. - A
bool
visited
, which is initialized tofalse
. - A vector of
Node
pointers namedneighbors
.
- A
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: react
- Opened files (when workspace is loaded): n/a
-
userCode:
export CXX=g++-7
export CXXFLAGS=-std=c++17
cmake_tests() {
/usr/local/bin/cmake -DTESTING="RMNodeClass" "$1"
}
export -f cmake_tests
Solution
The Node Class